use serde::{Deserialize, Serialize};
use ts_rs::TS;

use super::IndicatorActionWrap;

/// Struct to hold the results of Chaikin Money Flow (CMF) indicator.
///
/// 参见 [CMF](https://docs.rs/yata/latest/yata/indicators/struct.ChaikinMoneyFlow.html)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct CMF {
    ///1 signal
    /// When main value goes above zero, then returns full buy signal. When main value goes below zero, then returns full sell signal. Otherwise no signal
    pub signal0: Option<IndicatorActionWrap>,

    /// 1 values
    /// main value
    /// Range in (-inf; +inf)
    pub main: f64,
}

/// Configuration for the Chaikin Money Flow (CMF) indicator.
/// This oscillator is designed to measure the buying and selling pressure of an asset over a specified period
/// by assessing the location of the closing price within the daily high-low range and combining this with volume data.
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct CMFConfig {
    ///main length size. Default is 20
    ///Range in [2; PeriodType::MAX)
    pub size: u8,
}

impl Default for CMFConfig {
    fn default() -> Self {
        Self { size: 20 }
    }
}
